package com.crealth.memcached;

import com.crealth.db.ConsumerDb;
import com.crealth.model.ConsumerWorkModel;

public class ConsumerWorkCached {
	private static final String workKeyPrefix = "work_csmid_";
	
	public static ConsumerWorkModel selectConsumerWork(int consumerID) {
		String key = workKeyPrefix + consumerID;
		Object obj = MemcachedMgr.cachedClient.get(key);
		ConsumerWorkModel selfWork = null;
		if (obj != null) {
			selfWork = (ConsumerWorkModel)obj;
		}
		else {
			selfWork = ConsumerDb.selectConsumerWork(consumerID);
			if (selfWork != null) {
				MemcachedMgr.cachedClient.set(key, selfWork);
			}
		}
		
		return selfWork;
	}
	
	public static void deleteCached(int consumerID) {
		String key = workKeyPrefix + consumerID;
		MemcachedMgr.cachedClient.delete(key);
	}
	
}
